/*----------------------------------------------------------------------------
Owner(s): Shane Whitfield
$Copyright: $
$Id: 

Purpose  : 
----------------------------------------------------------------------------*/

#pragma once

#include "wave.h"
#include "gomgr.h"
#include "bbmath.h"
#include "gomgr.h"

/*--------------------------------------------------------------------------*/
// Forward declarations
class CWave;

/*--------------------------------------------------------------------------*/
// Class CLevel declaration.
class CLevel
{
public:
				CLevel(const char* levelFileName);
				~CLevel();
	static void	SetFileLoader(bool (*systemFileLoader)(const char* i_filename, CLevel* io_level));
	void		Update();
	void		Start();
	bool		IsComplete() const {
					return m_state == EState_Complete; }
	void		On_MineralCount(float i_mineralCount);
	void		On_AddMinerals(float i_x, float i_y, float i_mineralCount);
	void		On_AddWave(const char* i_fileName, float i_x, float i_y);
	void		On_AddPause(float i_secs);
	void		On_DisplayTimer(float i_secs);
	void		On_GoalSurviveWave();
	void		On_GoalCollectMinerals(float i_mineralCount);
	void		On_Spawn(const char* i_spawnClass, float i_x, float i_y);
	void		On_AddSystemMessage(const char* i_title, const char* i_message, const char* i_accept);
		
private:

	class CLevelCommand
	{
	public:
						CLevelCommand(){}
		virtual void	Execute() {}
		virtual bool	IsComplete() const = 0;
		virtual void	Update() {}
	};
	
	class CLevelCommandWave : public CLevelCommand
	{
	public:
						CLevelCommandWave(const char* i_fileName, const Vector2f& i_pos) {
							m_wave = NULL; strcpy(m_fileName, i_fileName); m_pos = i_pos; }
		virtual void	Execute();
		virtual bool	IsComplete() const {
							return true; }
		const CWave*	GetWave() const {
							return m_wave; }
		
	private:
		char			m_fileName[100];
		Vector2f		m_pos;
		CWave*			m_wave;
	};
	
	class CLevelCommandGoalCollect : public CLevelCommand
	{
	public:
						CLevelCommandGoalCollect(float i_mineralCount);
		virtual bool	IsComplete() const;	
		
	private:
		float	m_mineralCount;
	};
	
	class CLevelCommandMessage : public CLevelCommand
	{
	public:
						CLevelCommandMessage(const char* i_title, const char* i_message, const char* i_accept);
						~CLevelCommandMessage();
		virtual void	Execute();
		virtual bool	IsComplete() const;	
		
	private:
		char*	m_title;
		char*	m_message;
		char*	m_accept;
	};
	
	class CLevelCommandWait : public CLevelCommand
	{
	public:
						CLevelCommandWait(const CLevelCommandWave*	i_waveCommand) {
							m_waveCommand = i_waveCommand; }
		virtual void	Execute() {printf("executing wait\n");}
		virtual bool	IsComplete() const;	
		
	private:
		const CLevelCommandWave*	m_waveCommand;
	};
	
	class CLevelCommandPause : public CLevelCommand
	{
	public:
						CLevelCommandPause(float i_duration) {
							m_duration = i_duration; }
		virtual void	Execute();
		virtual bool	IsComplete() const;	
		
	private:
		float	m_duration;
		float	m_tStart;
	};
	
	class CLevelCommandDisplayTimer : public CLevelCommand
	{
	public:
						CLevelCommandDisplayTimer(float i_duration) {
							m_duration = i_duration; }
		virtual void	Execute();
		virtual bool	IsComplete() const {
							return true; }
		
	private:
		float	m_duration;
	};

	enum EState
	{
		EState_WaitingToStart,
		EState_ExecuteNextCommand,
		EState_Executing,
		EState_Complete
	};
	
	void	load(const char* i_levelFileName);
	void	setState(EState i_state);
	
	float						m_twave;
	CWave*						m_wave;
	EState						m_state;
	float						m_tState;
	std::vector<CLevelCommand*>	m_levelCommands;
	int							m_curCommand;
	const CLevelCommandWave*	m_lastWave;
};

/*-----------------------------------EOF!-----------------------------------*/